package logs

import (
	"github.com/astaxie/beego/logs"
	"github.com/ztrue/tracerr"
	"strings"
)

// Debug uses fmt.Sprint to construct and log a message.
func Debug(f interface{}, v ...interface{}) {
	logs.Debug(f, v...)
}

// Info uses fmt.Sprint to construct and log a message.
func Info(f interface{}, v ...interface{}) {
	logs.Info(f, v...)
}

// Warning uses fmt.Sprint to construct and log a message.
func Warning(f interface{}, v ...interface{}) {
	logs.Warning(f, v...)
}

// Error uses fmt.Sprint to construct and log a message.
func Error(f interface{}, v ...interface{}) {
	logs.Error(f, v...)
}

// Critical uses fmt.Sprint to construct and log a message, then panics.
func Critical(f interface{}, v ...interface{}) {
	logs.Critical(f, v...)
}

// Emergency uses fmt.Sprint to construct and log a message, then calls os.Exit.
func Emergency(f interface{}, v ...interface{}) {
	logs.Emergency(f, v...)
}

func ErrorWithStack(err error, deep ...int) {
	stack := tracerr.StackTrace(err)
	var info = []string{err.Error()}
	var d = 2
	if len(deep) > 0 {
		d = deep[0]
	}
	for i, f := range stack {
		if i == d {
			break
		}
		info = append(info, f.String())
	}
	logs.Error("%v", strings.Join(info, "\n\t"))
}
